<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <link type="text/css" rel="stylesheet" th:href="@{/css/layui.css}"/>
    <link type="text/css" rel="stylesheet" th:href="@{/css/layer.css}"/>
</head>
<body>
<form class="layui-form">
    <div class="layui-tab"><!--最大层-->
        <ul class="layui-tab-title"><!--内层-->
            <li class="layui-this">客户信息</li>
            <li>紧急联系人信息</li>
        </ul>
        <div class="layui-tab-content">
            <!--客户信息-->
            <div class="layui-tab-item layui-show">



                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="clientname"    class="layui-input" id="clientname">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input" id="phone">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">客户类型</label>
                    <div class="layui-input-block">
                        <select name="clienttype" lay-filter="aihao">
                            <opion value=""></opion>
                            <option value="业主">业主</option>
                            <!--<option value="租户" selected="">租户</option>-->

                        </select>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">证件类型</label>
                    <div class="layui-input-block">
                        <select th:name="certificatetype" lay-filter="aihao">
                            <option value="身份证" selected="">身份证</option>

                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">证件号</label>
                    <div class="layui-input-block">
                        <input type="text" name="certificateno" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input" id="certificateno">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="gender" value="男" title="男" checked="">
                        <input type="radio" name="gender" value="女" title="女">
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">民族</label>
                    <div class="layui-input-block">
                        <select th:name="nation" lay-filter="aihao">
                            <option value="汉族">汉族</option>
                            <option value="回族" selected="">回族</option>

                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">家庭住址</label>
                <div class="layui-input-block">
                    <textarea  name="natives" placeholder="请输入内容" class="layui-textarea" id="natives"></textarea>
                </div>
            </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">教育程度</label>
                    <div class="layui-input-block">
                        <select th:name="educationid" lay-filter="aihao">
                            <option th:each="e:${ed}" th:value="${e.educationid}" th:text="${e.education}"></option>

                        </select>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">开户行</label>
                    <div class="layui-input-block">
                        <select name="openbank" lay-filter="aihao">
                            <opion value=""></opion>
                            <option value="中国银行">中国银行</option>
                            <option value="建设银行" selected="">建设银行</option>
                            <option value="邮政银行">邮政银行</option>
                            <option value="农业银行" selected="">农业银行</option>

                        </select>
                    </div>
                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">卡号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="banknumber"  class="layui-input" id="banknumber" lay-verify="required|number">
                    </div>
                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">添加日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="addtime" id="date1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>



            </div><!--客户信息闭合-->




            <!--紧急联系人-->
            <div class="layui-tab-item">



                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="relationname"    class="layui-input" id="relationname">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="emergencyphone" lay-verify="required|phone" autocomplete="off" class="layui-input" id="emergencyphone">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">家庭住址</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" class="layui-textarea" name="address" id="address"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">工作单位</label>
                    <div class="layui-input-block">
                        <input type="text" name="company"  lay-verify="title" autocomplete="off" id="company" class="layui-input">
                    </div>
                </div>




            </div><!--紧急联系人闭合-->

        </div><!--内层-->
        <div style="margin-left: 210px">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="tijiao">提交</button>
        </div>
    </div><!--最大层-->

</form>

<script type="text/javascript">



    layui.use(['form', 'layer', 'laydate','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,element = layui.element
            ,$=layui.jquery;

        $("#banknumber").change(function(){
            var account = $(this).val().length;

            // var reg = /^\d{19}$/g;     // 以19位数字开头，以19位数字结尾
            if( account!=19)
            {
                alert("格式错误，应该是19位数字！");
            }

        })



        //日期
        laydate.render({
            elem: '#date',
            trigger:'click'
        });
        laydate.render({
            elem: '#date1',
            trigger:'click'
        });
        //监听提交
        form.on('submit(tijiao)', function(data){
            //data.field表单所有信息

            if($("#clientname").val()==""){
                alert("客户姓名不能为空！") ;
                return false;
            }
            if($("#natives").val()==""){
                alert("家庭住址不能为空！") ;
                return false;
            }
            if($("#company").val()==""){
                alert("工作单位不能为空！") ;
                return false;
            }
            if($("#banknumber").val()==""){
                alert("银行卡号不能为空！") ;
                return false;
            }
            if($("#relationname").val()==""){
                alert("联系人姓名不能为空！") ;
                return false;
            }
            if($("#emergencyphone").val()==""){
                alert("联系人电话不能为空！") ;
                return false;
            }
            if($("#address").val()==""){
                alert("联系人住址不能为空！") ;
                return false;
            }
            if($("#company").val()==""){
                alert("联系人工作单位不能为空！") ;
                return false;
            }

            else {
                $.post("addClient", data.field, function (result) {
                        if (result.data == false) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            })

                        }
                        else {
                            layer.msg(result.msg, {
                                    icon: 1,
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                },

                                function () {
                                    //刷新父页面
                                    // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    // parent.layer.close(index)
                                    parent.window.location.reload();
                                });
                        }
                    }
                );
                return false;
            }
        });

        //重置清空文本框
        $("#reset").click(function () {
            $("#clientname").val("");
            $("#phone").val("");
            $("#certificateno").val("");
            $("#natives").val("");
            $("#banknumber").val("");
            $("#date1").val("");
            $("#company").val("");
            $("#emergencyphone").val("");
            $("#relationname").val("");
            form.render();

        })
    });
</script>

</body>
</html>